<template>
  <div class="tableGreenBox">
    <el-table class="tableGreen" :data="tableData" style="width: 100%">
      <el-table-column label="农资名称" header-align="center" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="登记证号" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.date }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="类别" header-align="center" align="center" width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.typeFormat }}</span>
        </template>
      </el-table-column>
      <el-table-column label="生产厂家" header-align="center" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.manufacturer }}</span>
        </template>
      </el-table-column>
      <el-table-column label="规格（公斤/袋）" header-align="center" align="center" width="160">
        <template slot-scope="scope">
          <span>{{ scope.row.specifications }}</span>
        </template>
      </el-table-column>
      <el-table-column label="库存（公斤）" header-align="center" align="center" width="160">
        <template slot-scope="scope">
          <span>{{ scope.row.remainingQuantity }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" header-align="center" align="center" width="100">
        <template slot-scope="scope">
          <el-button
            type="text"
            class="greenColorBtn"
            size="mini"
            :disabled="addBtnDisabled(scope.row.agriDicId)"
            @click="handleEdit(scope.row)"
            >
            选择
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :current-page.sync="paramsPage.current"
        :page-size="paramsPage.pageSize"
        layout="prev, pager, next, jumper"
        :total="dialogTotal"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getFarmsStockInventoryApi
} from '@/api/mission'
import { getSysSonDictListApi } from '@/api/dict'
export default {
  name: 'SevencolorUserFarmStockDialog',
  props: {
    farmStockList: {
      type: Array
    },
    total: {
      type: Number
    },
    farmStockAddList: {
      type: Array
    }
  },

  data () {
    return {
      currentPage: 1,
      tableData: [],
      dialogTotal: null,
      paramsPage: {
        current: 1,
        pageSize: 6,
        baseId: 0
      }
    }
  },

  mounted () {
    this.paramsPage.baseId = this.$store.getters.userInfo.baseId
    this.tableData = this.farmStockList
    this.dialogTotal = this.total
  },

  methods: {
    // 按钮禁用判断
    addBtnDisabled (id) {
      // console.log(id)
      // console.log(this.farmStockAddList)
      for (let i = 0; i < this.farmStockAddList.length; i++) {
        if (this.farmStockAddList[i].agriId === id) {
          return true
        }
      }
      return false
    },
    // 选中
    handleEdit (val) {
      this.$emit('addFarmStock', val)
      this.paramsPage.current = 1
    },
    getSearch (keyWord, type) {
      this.paramsPage.name = keyWord
      this.paramsPage.type = type
      this.handleCurrentChange()
    },
    async handleCurrentChange () {
      const res = await getFarmsStockInventoryApi(this.paramsPage)
      this.tableData = res.data.records
      this.dialogTotal = res.data.total
    }
  }
}
</script>
<style lang="scss" scoped>
.pagination {
  margin: 2vh 0 0 0;
  text-align: right;
  ::v-deep .el-input__inner {
  width: 0.5rem !important;
}
}

</style>
